package ru.spb.osll.myfit.client.dialog;

import java.util.Map;
import java.util.TreeMap;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.MultiWordSuggestOracle.MultiWordSuggestion;

public class TableCreatorDialog extends InputDialog {
  
	private TreeMap<String, String> m_fixtureNames = new TreeMap<String, String>();	

	public TableCreatorDialog(DialogEventListener listener) {    
	  super(listener);
	  setText("Add test table:");
	  defineItems () ;
	  
	  m_cbButtonOk.setText("Add");
	  m_cbButtonOk.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        if ((!m_suggestBox.getText().isEmpty())
          && (m_fixtureNames.containsKey(m_suggestBox.getText()))){
          String tableName = m_fixtureNames.get(m_suggestBox.getText());
          m_listener.createElement(tableName, m_sourceEvent);  
        }
          hide();
          m_sourceEvent = null;
        }
      });
    }
	
	
	public void setFixturesName(TreeMap<String, String> tables){
	  m_fixtureNames = tables;
	  defineItems();
	    
	}
	
	 public void defineItems () {	    
	    for (Map.Entry<String, String> entry: m_fixtureNames.entrySet()) {
	      String hint = entry.getKey();
	      oracle.add(hint);
	      MultiWordSuggestion suggestion = new MultiWordSuggestion(hint,hint);
	      suggestions.add(suggestion);
	    } 
	    oracle.setDefaultSuggestions(suggestions);
	 }  
	   
}
